package cn.iocoder.yudao.module.picturebook.dal.mysql.readingrecord;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.picturebook.dal.dataobject.readingrecord.ReadingRecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.picturebook.controller.admin.readingrecord.vo.*;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户阅读记录 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ReadingRecordMapper extends BaseMapperX<ReadingRecordDO> {



    default PageResult<ReadingRecordDO> selectPage(ReadingRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ReadingRecordDO>()
                .eqIfPresent(ReadingRecordDO::getUserId, reqVO.getUserId())
                .orderByDesc(ReadingRecordDO::getUpdateTime)
        );

    }



    void deleteFavorites(@Param("bookId") Long bookId,@Param("userId") Long userId);

    ReadingRecordDO getReadingRecord(@Param("userId") Long userId, @Param("bookId") Long bookId);

    void updateReadingRecord(ReadingRecordDO readingRecord);

    int getDayCount(@Param("userId") Long userId, @Param("now") LocalDateTime now);

    int getWeekCount(@Param("userId") Long userId, @Param("weekAgo") LocalDateTime weekAgo, @Param("now") LocalDateTime now);

    int getTotalDays(@Param("userId") Long userId);

    int getTotalCount(@Param("userId") Long userId);

    int getTodayCount(@Param("userId") Long userId,@Param("today") LocalDate today);

    List<Integer> getRecordByUserId(@Param("userId") Long userId, @Param("checkinDate") LocalDate checkinDate);

    int getReadingRecordByThree(@Param("threeDaysAgo") LocalDate threeDaysAgo,@Param("today") LocalDate today);

    Integer getTodayCountByTime(LocalDate now);
}